package cn.dansj.common.utils.bean;

import cn.dansj.common.utils.enums.GlobalEnv;
import cn.dansj.common.utils.transfer.DefaultMethods;

import java.io.Serializable;

/*
 * 请求返回信息
 * */
public class Return<T> extends DefaultMethods implements Serializable {
    public static final Return<String> SUCCESS = Return.T(true, "");
    public static final Return<String> FAIL = Return.T(false, "");

    private static final long serialVersionUID = GlobalEnv.SerialVersionUID;

    private String message;
    private boolean status;
    public static final int SUCCESS_CODE = 200;
    public static final int FAIL_CODE = 500;

    private int responseCode = SUCCESS_CODE;

    private T data;
    private Long totalRecord;

    public static <T> Return<T> T(T data) {
        return new Return<T>().setData(data).setStatus(true).setResponseCode(SUCCESS_CODE);
    }

    public static <T> Return<T> T(boolean status, String message) {
        return new Return<T>().setStatus(status).setMessage(message).setResponseCode(status ? SUCCESS_CODE : FAIL_CODE);
    }

    public boolean getStatus() {
        return status;
    }

    public Return<T> setStatus(boolean status) {
        this.status = status;
        this.responseCode = status ? SUCCESS_CODE : FAIL_CODE;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Return<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public T getData() {
        return data;
    }

    public Return<T> setData(T data) {
        this.data = data;
        return this;
    }

    public int getResponseCode() {
        return responseCode;
    }

    public Return<T> setResponseCode(int responseCode) {
        this.responseCode = responseCode;
        return this;
    }

    public Long getTotalRecord() {
        return totalRecord;
    }

    public Return<T> setTotalRecord(long totalRecord) {
        this.totalRecord = totalRecord;
        return this;
    }
}
